<!-- eslint-disable vue/valid-v-slot -->
<template>
  <div class="main-container">
    <TableBody>
      <template #header>
        <TableHeader ref="tableHeaderRef" :show-filter="false">
          <template #search-content>
            <a-form ref="serchForm" :model="form" :style="{ width: '100%' }">
              <a-row :gutter="24">
                <a-col :span="4">
                  <a-form-item field="orderNumber" hide-label>
                    <a-input v-model="form.orderNumber" placeholder="请输入订单号" allow-clear />
                  </a-form-item>
                </a-col>
                <a-col :span="4">
                  <a-form-item field="cards" hide-label>
                    <a-input v-model="form.cards" placeholder="请输入卡号" allow-clear>
                      <template #suffix>
                        <icon-plus @click="open(1)" style="cursor: pointer" />
                      </template>
                    </a-input>
                  </a-form-item>
                </a-col>
                <a-col :span="4">
                  <a-form-item field="isZhiShu" hide-label>
                    <a-select v-model="form.isZhiShu" placeholder="请选择订单类型">
                      <a-option :value="0">所有订单</a-option>
                      <a-option :value="1">直属订单</a-option>
                    </a-select>
                  </a-form-item>
                </a-col>
                <a-col :span="4">
                  <a-form-item field="userIdList" hide-label>
                    <a-select
                      v-model="form.userIdList"
                      placeholder="请选择客户"
                      multiple
                      :max-tag-count="1"
                      allow-clear
                      allow-search
                      :options="userList"
                      :virtual-list-props="{ height: 200 }"
                    />
                  </a-form-item>
                </a-col>
                <a-col :span="4">
                  <a-form-item field="channelIdList " hide-label>
                    <!-- <a-select
                      v-model="form.channelIdList"
                      placeholder="请选择渠道"
                      multiple
                      :max-tag-count="1"
                      allow-clear
                      allow-search
                    >
                      <a-option v-for="item in channel" :key="item.id" :value="item.id">{{
                        item.name
                      }}</a-option>
                    </a-select> -->
                    <a-tree-select
                      v-model="form.channelIdList"
                      :allow-search="true"
                      :allow-clear="true"
                      :tree-checkable="true"
                      :filter-tree-node="useCommon.filterTreeNode"
                      :tree-check-strictly="false"
                      :data="channel"
                      :max-tag-count="1"
                      placeholder="请选择渠道"
                    />
                  </a-form-item>
                </a-col>
                <a-col :span="4">
                  <a-form-item field="seriesIdList" hide-label>
                    <a-select
                      v-model="form.seriesIdList"
                      placeholder="请选择系列"
                      multiple
                      :max-tag-count="1"
                      allow-clear
                      allow-search
                    >
                      <a-option v-for="item in series" :key="item.id" :value="item.id">{{
                        item.name
                      }}</a-option>
                    </a-select>
                  </a-form-item>
                </a-col>
                <a-col :span="4">
                  <a-form-item field="operatorIdList" hide-label>
                    <a-select
                      v-model="form.operatorIdList"
                      placeholder="请选择运营商"
                      multiple
                      :max-tag-count="1"
                      allow-clear
                    >
                      <a-option :value="0">中国移动</a-option>
                      <a-option :value="1">中国联通</a-option>
                      <a-option :value="2">中国电信</a-option>
                      <a-option :value="3">中国广电</a-option>
                    </a-select>
                  </a-form-item>
                </a-col>
                <a-col :span="4">
                  <a-form-item field="payTypeIdList" hide-label>
                    <a-select
                      v-model="form.payTypeIdList"
                      placeholder="请选择充值途径"
                      multiple
                      :max-tag-count="1"
                      allow-clear
                    >
                      <a-option :value="0">余额</a-option>
                      <a-option :value="1">支付宝</a-option>
                      <a-option :value="2">微信</a-option>
                    </a-select>
                  </a-form-item>
                </a-col>
                <a-col :span="4">
                  <a-form-item field="state" hide-label>
                    <a-select v-model="form.state" placeholder="请选择订单状态" allow-clear>
                      <a-option :value="0">正常</a-option>
                      <a-option :value="1">退款</a-option>
                    </a-select>
                  </a-form-item>
                </a-col>
                <a-col :span="4">
                  <a-form-item field="addPayTime" hide-label>
                    <a-date-picker
                      style="width: 100%"
                      v-model="form.addPayTime"
                      show-time
                      placeholder="请选择开始充值时间"
                      :time-picker-props="{ defaultValue: '12:00:00' }"
                      format="YYYY-MM-DD HH:mm:ss"
                      allow-clear
                      :shortcuts="[
                        {
                          label: '今日',
                          value: () => (
                            (form.addPayTime = $dayjs('00:00:00', 'HH:mm:ss').format(
                              'YYYY-MM-DD HH:mm:ss'
                            )),
                            (form.endPayTime = $dayjs('23:59:59', 'HH:mm:ss').format(
                              'YYYY-MM-DD HH:mm:ss'
                            ))
                          ),
                        },
                        {
                          label: '昨日',
                          value: () => (
                            (form.addPayTime = $dayjs('00:00:00', 'HH:mm:ss')
                              .subtract(1, 'day')
                              .format('YYYY-MM-DD HH:mm:ss')),
                            (form.endPayTime = $dayjs('23:59:59', 'HH:mm:ss')
                              .subtract(1, 'day')
                              .format('YYYY-MM-DD HH:mm:ss'))
                          ),
                        },
                        {
                          label: '七日',
                          value: () => (
                            (form.addPayTime = $dayjs('00:00:00', 'HH:mm:ss')
                              .subtract(6, 'day')
                              .format('YYYY-MM-DD HH:mm:ss')),
                            (form.endPayTime = $dayjs().format('YYYY-MM-DD HH:mm:ss'))
                          ),
                        },
                        {
                          label: '本月',
                          value: () => (
                            (form.addPayTime = $dayjs('01 00:00:00', 'DD HH:mm:ss').format(
                              'YYYY-MM-DD HH:mm:ss'
                            )),
                            (form.endPayTime = $dayjs().format('YYYY-MM-DD HH:mm:ss'))
                          ),
                        },
                        {
                          label: '上月',
                          value: () => (
                            (form.addPayTime = $dayjs(`01 00:00:00`, 'DD HH:mm:ss')
                              .subtract(1, 'month')
                              .format('YYYY-MM-DD HH:mm:ss')),
                            (form.endPayTime = $dayjs()
                              .subtract(1, 'month')
                              .endOf('month')
                              .format('YYYY-MM-DD HH:mm:ss'))
                          ),
                        },
                      ]"
                    />
                  </a-form-item>
                </a-col>
                <a-col :span="4">
                  <a-form-item field="endFlowRefreshTime" hide-label>
                    <a-date-picker
                      style="width: 100%"
                      v-model="form.endPayTime"
                      show-time
                      placeholder="请选择结束充值时间"
                      :time-picker-props="{ defaultValue: '12:00:00' }"
                      format="YYYY-MM-DD HH:mm:ss"
                      allow-clear
                      :shortcuts="[
                        {
                          label: '今日',
                          value: () => (
                            (form.addPayTime = $dayjs('00:00:00', 'HH:mm:ss').format(
                              'YYYY-MM-DD HH:mm:ss'
                            )),
                            (form.endPayTime = $dayjs('23:59:59', 'HH:mm:ss').format(
                              'YYYY-MM-DD HH:mm:ss'
                            ))
                          ),
                        },
                        {
                          label: '昨日',
                          value: () => (
                            (form.addPayTime = $dayjs('00:00:00', 'HH:mm:ss')
                              .subtract(1, 'day')
                              .format('YYYY-MM-DD HH:mm:ss')),
                            (form.endPayTime = $dayjs('23:59:59', 'HH:mm:ss')
                              .subtract(1, 'day')
                              .format('YYYY-MM-DD HH:mm:ss'))
                          ),
                        },
                        {
                          label: '七日',
                          value: () => (
                            (form.addPayTime = $dayjs('00:00:00', 'HH:mm:ss')
                              .subtract(6, 'day')
                              .format('YYYY-MM-DD HH:mm:ss')),
                            (form.endPayTime = $dayjs().format('YYYY-MM-DD HH:mm:ss'))
                          ),
                        },
                        {
                          label: '本月',
                          value: () => (
                            (form.addPayTime = $dayjs('01 00:00:00', 'DD HH:mm:ss').format(
                              'YYYY-MM-DD HH:mm:ss'
                            )),
                            (form.endPayTime = $dayjs().format('YYYY-MM-DD HH:mm:ss'))
                          ),
                        },
                        {
                          label: '上月',
                          value: () => (
                            (form.addPayTime = $dayjs(`01 00:00:00`, 'DD HH:mm:ss')
                              .subtract(1, 'month')
                              .format('YYYY-MM-DD HH:mm:ss')),
                            (form.endPayTime = $dayjs()
                              .subtract(1, 'month')
                              .endOf('month')
                              .format('YYYY-MM-DD HH:mm:ss'))
                          ),
                        },
                      ]"
                    />
                  </a-form-item>
                </a-col>
                <a-col :span="4">
                  <a-form-item field="addEndTime" hide-label>
                    <a-date-picker
                      style="width: 100%"
                      v-model="form.addEndTime"
                      show-time
                      placeholder="请选择开始过期时间"
                      :time-picker-props="{ defaultValue: '12:00:00' }"
                      format="YYYY-MM-DD HH:mm:ss"
                      allow-clear
                      :shortcuts="[
                        {
                          label: '今日',
                          value: () => (
                            (form.addEndTime = $dayjs('00:00:00', 'HH:mm:ss').format(
                              'YYYY-MM-DD HH:mm:ss'
                            )),
                            (form.endEndTime = $dayjs('23:59:59', 'HH:mm:ss').format(
                              'YYYY-MM-DD HH:mm:ss'
                            ))
                          ),
                        },
                        {
                          label: '昨日',
                          value: () => (
                            (form.addEndTime = $dayjs('00:00:00', 'HH:mm:ss')
                              .subtract(1, 'day')
                              .format('YYYY-MM-DD HH:mm:ss')),
                            (form.endEndTime = $dayjs('23:59:59', 'HH:mm:ss')
                              .subtract(1, 'day')
                              .format('YYYY-MM-DD HH:mm:ss'))
                          ),
                        },
                        {
                          label: '七日',
                          value: () => (
                            (form.addEndTime = $dayjs('00:00:00', 'HH:mm:ss')
                              .subtract(6, 'day')
                              .format('YYYY-MM-DD HH:mm:ss')),
                            (form.endEndTime = $dayjs().format('YYYY-MM-DD HH:mm:ss'))
                          ),
                        },
                        {
                          label: '本月',
                          value: () => (
                            (form.addEndTime = $dayjs('01 00:00:00', 'DD HH:mm:ss').format(
                              'YYYY-MM-DD HH:mm:ss'
                            )),
                            (form.endEndTime = $dayjs().format('YYYY-MM-DD HH:mm:ss'))
                          ),
                        },
                        {
                          label: '上月',
                          value: () => (
                            (form.addEndTime = $dayjs(`01 00:00:00`, 'DD HH:mm:ss')
                              .subtract(1, 'month')
                              .format('YYYY-MM-DD HH:mm:ss')),
                            (form.endEndTime = $dayjs()
                              .subtract(1, 'month')
                              .endOf('month')
                              .format('YYYY-MM-DD HH:mm:ss'))
                          ),
                        },
                      ]"
                    />
                  </a-form-item>
                </a-col>
                <a-col :span="4">
                  <a-form-item field="endEndTime" hide-label>
                    <a-date-picker
                      style="width: 100%"
                      v-model="form.endEndTime"
                      show-time
                      placeholder="请选择结束过期时间"
                      :time-picker-props="{ defaultValue: '12:00:00' }"
                      format="YYYY-MM-DD HH:mm:ss"
                      allow-clear
                      :shortcuts="[
                        {
                          label: '今日',
                          value: () => (
                            (form.addEndTime = $dayjs('00:00:00', 'HH:mm:ss').format(
                              'YYYY-MM-DD HH:mm:ss'
                            )),
                            (form.endEndTime = $dayjs('23:59:59', 'HH:mm:ss').format(
                              'YYYY-MM-DD HH:mm:ss'
                            ))
                          ),
                        },
                        {
                          label: '昨日',
                          value: () => (
                            (form.addEndTime = $dayjs('00:00:00', 'HH:mm:ss')
                              .subtract(1, 'day')
                              .format('YYYY-MM-DD HH:mm:ss')),
                            (form.endEndTime = $dayjs('23:59:59', 'HH:mm:ss')
                              .subtract(1, 'day')
                              .format('YYYY-MM-DD HH:mm:ss'))
                          ),
                        },
                        {
                          label: '七日',
                          value: () => (
                            (form.addEndTime = $dayjs('00:00:00', 'HH:mm:ss')
                              .subtract(6, 'day')
                              .format('YYYY-MM-DD HH:mm:ss')),
                            (form.endEndTime = $dayjs().format('YYYY-MM-DD HH:mm:ss'))
                          ),
                        },
                        {
                          label: '本月',
                          value: () => (
                            (form.addEndTime = $dayjs('01 00:00:00', 'DD HH:mm:ss').format(
                              'YYYY-MM-DD HH:mm:ss'
                            )),
                            (form.endEndTime = $dayjs().format('YYYY-MM-DD HH:mm:ss'))
                          ),
                        },
                        {
                          label: '上月',
                          value: () => (
                            (form.addEndTime = $dayjs(`01 00:00:00`, 'DD HH:mm:ss')
                              .subtract(1, 'month')
                              .format('YYYY-MM-DD HH:mm:ss')),
                            (form.endEndTime = $dayjs()
                              .subtract(1, 'month')
                              .endOf('month')
                              .format('YYYY-MM-DD HH:mm:ss'))
                          ),
                        },
                      ]"
                    />
                  </a-form-item>
                </a-col>
                <a-col :span="4">
                  <a-form-item field="addPayAmount" hide-label>
                    <a-input-group style="width: 100%">
                      <a-input
                        hide-button
                        v-model="form.addPayAmount"
                        allow-clear
                        placeholder="开始充值余额"
                      />
                      <a-input
                        hide-button
                        v-model="form.endPayAmount"
                        allow-clear
                        placeholder="结束充值余额"
                      />
                    </a-input-group>
                  </a-form-item>
                </a-col>
                <a-col :span="4">
                  <a-form-item field="addPayAmount" hide-label>
                    <a-input-group style="width: 100%">
                      <a-input
                        hide-button
                        v-model="form.addCounts"
                        allow-clear
                        placeholder="开始充值次数"
                      />
                      <a-input
                        hide-button
                        v-model="form.endCounts"
                        allow-clear
                        placeholder="结束充值次数"
                      />
                    </a-input-group>
                  </a-form-item>
                </a-col>
                <a-col :span="4">
                  <a-form-item field="btns" hide-label>
                    <a-space :size="15">
                      <a-button
                        type="primary"
                        v-permission="speedOrderList"
                        html-type="submit"
                        @click="doRefresh(1)"
                        ><template #icon>
                          <icon-search />
                        </template>
                        <!-- Use the default slot to avoid extra spaces -->
                        <template #default>搜索</template></a-button
                      >
                      <a-button v-permission="speedOrderList" @click="reset"
                        ><template #icon>
                          <icon-sync theme="outline" size="14" />
                        </template>
                        <!-- Use the default slot to avoid extra spaces -->
                        <template #default>重置</template></a-button
                      >
                    </a-space>
                  </a-form-item>
                </a-col>
              </a-row>
            </a-form>
          </template>
        </TableHeader>
      </template>
      <template #table-config>
        <a-space :size="15">
          <a-button v-permission="speedExport" @click="cardBalanceExports" type="outline">
            <!-- Use the default slot to avoid extra spaces -->
            <template #default>导出</template>
          </a-button>
          <!-- <a-button @click="processVisible = true" type="outline"> -->
          <!-- Use the default slot to avoid extra spaces -->
          <!-- <template #default>批量审核</template>
          </a-button> -->
        </a-space>
        <a-space :size="15">
          <TableConfig
            @update-border="onUpdateBorder"
            @update-striped="onUpdateStriped"
            @refresh="doRefresh"
          />
        </a-space>
      </template>
      <template #default>
        <a-table
          :loading="tableLoading"
          :bordered="{ wrapper: true, cell: tables.bordered }"
          :stripe="(tables.striped as boolean)"
          :data="table.dataList"
          :pagination="false"
          :row-key="rowKey"
          :row-class-name="rowClassNameFun"
          :scroll="scroll"
          :scrollbar="{ type: 'track', outerClass: '', outerStyle: '' }"
          @change="handleChange"
        >
          <template #columns>
            <a-table-column
              v-for="item of tableColumns.list"
              :key="item.key"
              align="left"
              :title="(item.title as string)"
              :width="item.width"
              :data-index="(item.key as string)"
              :fixed="item.fixed"
              :ellipsis="true"
              :tooltip="true"
              :sortable="item.sortable"
            >
              <template v-if="item.key === 'card'" #cell="{ record }">
                <div class="ba">
                  <img
                    v-if="record.type === 0"
                    src="@/assets/order/y.jpg"
                    style="width: 16px; height: 16px; margin-right: 5px"
                    mode=""
                  />
                  <img
                    v-if="record.type === 1"
                    src="@/assets/order/zf.png"
                    style="width: 16px; height: 16px; margin-right: 5px"
                    mode=""
                  />
                  <img
                    v-if="record.type === 2"
                    src="@/assets/order/w.png"
                    style="width: 16px; height: 16px; margin-right: 5px"
                    mode=""
                  />
                  <img
                    v-if="record.type === 3"
                    src="@/assets/order/p.jpg"
                    style="width: 16px; height: 16px; margin-right: 5px"
                    mode=""
                  />
                  <span
                    @click="useCommon.routerOne(record.card)"
                    v-if="record.card.length >= 20"
                    class="card-number"
                    >{{ record.card }}</span
                  >
                  <span @click="useCommon.routerOne(record.card)" v-else>{{ record.card }}</span>
                  <icon-copy
                    class="aa"
                    style="color: #3491fa; padding-left: 5px"
                    @click="useCommon.copy(record.card)"
                  />

                  <icon-search
                    class="aa"
                    style="color: #3491fa; padding-left: 5px"
                    @click="detailFn(record)"
                  />
                </div>
              </template>
              <template v-if="item.key === 'state'" #cell="{ record }">
                <a-tag color="blue" v-if="record.state == 0">正常</a-tag>
                <a-tag color="red" v-if="record.state == 1">退款</a-tag>
              </template>
              <template v-else-if="item.key === 'type'" #cell="{ record }">
                <div v-if="record.type == 0"> 支付宝</div>
                <div v-if="record.type == 1"> 微信</div>
              </template>
              <template v-else-if="item.key === 'couponCount'" #cell="{ record }">
                <span>{{ record.vipTime }}{{ record.vipTimeType == 0 ? '天' : '月' }}</span>
              </template>
              <template v-else-if="item.key === 'payment_amount'" #cell="{ record }">
                <span>{{ record.paymentAmount }}</span>
              </template>
              <template v-else-if="item.key === 'couponAmount'" #cell="{ record }">
                <span>{{ record.couponAmount }}/{{ record.couponAllAmount }}</span>
              </template>
              <template v-else-if="item.key === 'userName'" #cell="{ record }">
                <span v-if="record.user">{{ record.user.userName }}</span>
                <span v-else>管理员 </span>
              </template>
              <template v-else-if="item.key === 'endUseTime'" #cell="{ record }">
                <span v-if="record.endUseTime">{{ record.endUseTime }}</span>
                <span v-else>---</span>
              </template>
              <template v-else-if="item.key === 'addUseTime'" #cell="{ record }">
                <span v-if="record.addUseTime">{{ record.addUseTime }}</span>
                <span v-else>---</span>
              </template>
              <template v-else-if="item.key === 'refundTime'" #cell="{ record }">
                <span v-if="record.refundTime">{{ record.refundTime }}</span>
                <span v-else>---</span>
              </template>
              <template v-else-if="item.key === 'refundRemarks'" #cell="{ record }">
                <span v-if="record.refundRemarks">{{ record.refundRemarks }}</span>
                <span v-else>---</span>
              </template>
              <template v-else-if="item.key === 'actions'" #cell="{ record }">
                <a-space :size="2">
                  <!-- <a-button
                    style="padding: 0px 4px"
                    type="text"
                    size="small"
                    @click="details1(record)"
                    >查看</a-button
                  >
                  <a-button
                    style="padding: 0px 4px"
                    type="text"
                    size="small"
                    @click="detailFn(record)"
                    >详情</a-button
                  > -->
                  <a-button
                    v-permission="speedTui"
                    @click="openState(record)"
                    style="padding: 0px 4px"
                    type="text"
                    size="small"
                    status="warning"
                    >退款</a-button
                  >
                </a-space>
              </template>
            </a-table-column>
          </template>
        </a-table>
        <div
          style="
            border: 1px solid rgba(229, 231, 235, var(--tw-border-opacity));
            border-top: 0;
            padding: 12px;
            text-align: left;
          "
          >统计：支付金额:{{ numForm }}元
        </div>
      </template>
      <template #footer>
        <TableFooter :pagination="pagination" />
      </template>
    </TableBody>
    <!-- 修改状态 -->
    <a-modal
      v-model:visible="stateVisible"
      @before-close="closeState"
      title="极速会员退款"
      width="800px"
      :mask-closable="false"
      title-align="start"
    >
      <div>
        <a-form ref="details" :model="detail">
          <a-row :gutter="16">
            <a-col :span="12">
              <a-form-item field="value1" label="订单ID" label-col-flex="80px">
                <a-input v-model="detail.id" readonly />
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item field="value2" label="会员名称" label-col-flex="80px">
                <a-input v-model="detail.vipName" readonly />
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item field="value3" label="充值时间" label-col-flex="80px">
                <a-input v-model="detail.payTime" readonly />
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item field="value3" label="支付金额" label-col-flex="80px">
                <a-input v-model="detail.paymentAmount" readonly />
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item field="value3" label="会员时间" label-col-flex="80px">
                <div class="radio-bcgs" style="text-align: left; padding-left: 13px"
                  >{{ detail.vipTime }}{{ detail.vipTimeType == 0 ? '天' : '月' }}</div
                >
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item field="value3" label="剩余时间" label-col-flex="80px">
                <div class="radio-bcgs" style="text-align: left; padding-left: 13px"
                  >{{ detail.surplusDays }}天</div
                >
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item field="value3" label="剩余比例" label-col-flex="80px">
                <div class="radio-bcgs" style="text-align: left; padding-left: 13px"
                  >{{ detail.percentage }}%</div
                >
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item field="value3" label="充值途径" label-col-flex="80px">
                <a-input v-model="detail.typeName" readonly />
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item field="value3" label="原路途径" label-col-flex="80px">
                <a-input v-model="detail.typeName" readonly />
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item field="value3" label="退款金额" label-col-flex="80px">
                <a-input-number
                  style="background-color: #fff; border: 1px solid #f2f3f5"
                  v-model="detail.refundAmount"
                  :min="0"
                  :max="detail.paymentAmount"
                />
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item field="value3" label="退款备注" label-col-flex="80px">
                <a-input
                  style="background-color: #fff; border: 1px solid #f2f3f5"
                  v-model="detail.refundRemarks"
                  placeholder="请输入退款备注"
                />
              </a-form-item>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <template #footer>
        <a-space style="width: 100%; display: flex; justify-content: center">
          <a-button type="primary" @click="refundFn(1)">原路退款</a-button>
          <a-button type="primary" status="success" @click="refundFn(0)">手动退款</a-button>
        </a-space>
      </template>
    </a-modal>
    <!-- 多卡搜索 -->
    <a-modal
      v-model:visible="cardsVisible"
      @before-close="colse"
      title="多条件搜索"
      width="400px"
      :mask-closable="false"
      title-align="start"
    >
      <a-textarea
        style="width: 100%"
        v-model="card"
        placeholder="请输入搜索条件，一行一个"
        allow-clear
      />
      <template #footer>
        <a-space>
          <a-button @click="cardsVisible = false">取消</a-button>
          <a-button type="primary" @click="cardsFn">确定</a-button>
        </a-space>
      </template>
    </a-modal>
    <!-- 详情 -->
    <a-modal v-model:visible="visible1" :mask-closable="false" width="800px" title="订单详情">
      <div>
        <a-descriptions :column="2" align="center" title="基础信息" bordered>
          <a-descriptions-item label="客户账号">{{
            detail.user ? detail.user.userName : '管理员'
          }}</a-descriptions-item>
          <a-descriptions-item label="订单类型"
            ><a-tag color="blue" v-if="detail.isFirst == true">首充{{ detail.number }}</a-tag>
            <a-tag color="red" v-if="detail.isFirst == false"
              >续订{{ detail.number }}</a-tag
            ></a-descriptions-item
          >
          <a-descriptions-item label="订单状态"
            ><a-tag color="blue" v-if="detail.state == 0">正常</a-tag>
            <a-tag color="red" v-if="detail.state == 1">退款</a-tag></a-descriptions-item
          >
          <a-descriptions-item label="优惠券名称">{{ detail.couponName }}</a-descriptions-item>
          <a-descriptions-item label="优惠券数量">{{ detail.couponCount }}张</a-descriptions-item>
          <a-descriptions-item label="优惠券总金额"
            >{{ detail.couponAllAmount }}元</a-descriptions-item
          >
          <a-descriptions-item label="剩余优惠券">{{ detail.couponName }}</a-descriptions-item>
          <a-descriptions-item label="剩余总金额">{{ detail.couponAmount }}元</a-descriptions-item>
        </a-descriptions>
        <a-descriptions
          :column="2"
          align="center"
          title="支付信息"
          style="margin-top: 20px"
          bordered
        >
          <a-descriptions-item label="充值途径">
            <div v-if="detail.type == 0"> 余额</div>
            <div v-if="detail.type == 1"> 支付宝</div>
            <div v-if="detail.type == 2"> 微信</div></a-descriptions-item
          >
          <a-descriptions-item label="充值金额">{{ detail.paymentAmount }}</a-descriptions-item>
          <a-descriptions-item label="充值时间">{{ detail.payTime }}</a-descriptions-item>
          <a-descriptions-item label="过期时间">{{ detail.endTime }}</a-descriptions-item>
          <a-descriptions-item label="首次使用">{{
            detail.addUseTime ? detail.addUseTime : '---'
          }}</a-descriptions-item>
          <a-descriptions-item label="最近使用">{{
            detail.endUseTime ? detail.endUseTime : '---'
          }}</a-descriptions-item>
          <a-descriptions-item label="客户IP">{{ detail.ip }}</a-descriptions-item>
          <a-descriptions-item label="支付ID">{{ detail.payTemplateId }}</a-descriptions-item>
          <!-- <a-descriptions-item label="支付名称">{{ detail.couponAmount }}元</a-descriptions-item>
          <a-descriptions-item label="支付商户号">{{ detail.outTradeNo }}元</a-descriptions-item> -->
          <a-descriptions-item label="商户订单号">{{ detail.outTradeNo }}</a-descriptions-item>
          <a-descriptions-item label="支付订单号">{{
            detail.tradeNo
          }}</a-descriptions-item></a-descriptions
        >
        <a-descriptions
          style="margin-top: 20px"
          :column="1"
          align="center"
          title="订单操作"
          bordered
        >
          <a-descriptions-item label="快捷操作">
            <a-button
              @click="openState(detail)"
              style="padding: 0px 4px"
              type="text"
              size="small"
              status="warning"
              >退款</a-button
            >
          </a-descriptions-item>
        </a-descriptions>
      </div>
      <template #footer>
        <a-space />
      </template>
    </a-modal>
  </div>
</template>

<script setup lang="ts">
  import { speedOrderList, speedTui, speedExport, speedDetail } from '@/api/url'
  import useCommonStore from '@/store/modules/common'
  import { usePagination, useRowKey, useTable } from '@/hooks/table'
  import { onMounted, reactive, ref } from 'vue'
  import { Message, Modal } from '@arco-design/web-vue'
  import { formpost, get } from '@/api/http'
  //排序
  function handleChange(data, extra, currentDataSource) {
    if (extra.sorter) {
      form.value.sortName = extra.sorter.field
      if (extra.sorter.direction == 'ascend') {
        form.value.sortType = 'asc'
      } else {
        form.value.sortType = 'desc'
      }
    } else {
      form.value.sortName = ''
      form.value.sortType = ''
    }
    doRefresh(1)
  }
  const pagination = usePagination(doRefresh)
  const rowKey = useRowKey('id')
  const table = useTable()
  const useCommon = useCommonStore()
  const channel: any = ref([])
  const series: any = ref([])
  const visible1 = ref(false)
  const details = ref()
  const card = ref('')
  const cardsVisible = ref(false)
  const ast = ref(0)
  const stateVisible = ref(false)
  const scroll = {
    x: 1500,
  }
  const detail: any = ref({
    createTime: '2023-08-24 16:12:25',
    id: 1,
    outRefundNo: '20230824161227935011',
    outTradeNo: '20230824161208245823',
    payTemplate: { merchantType: 0, merchantNo: '2021004101656942' },
    payTemplateId: 16,
    paymentAmount: 0,
    receivedAmount: 0,
    refundAmount: 0,
    serviceCharge: 0,
    tradeNo: '2023082422001412911428476242',
    type: 0,
    user: { userName: 'user' },
    userId: 41,
    series: { name: '执行程序', channel: { name: '迎梦云-老郭' } },
  })

  const typeText: any = ref('')
  const userList: any = ref([])

  const loading = ref(false)
  const form = ref({
    orderNumber: '', //    订单号
    card: '', //           卡号
    isZhiShu: 0, //      true直属 false所有
    userIdList: '', //     用户ID
    channelIdList: '', //  渠道ID
    seriesIdList: '', //   系列ID
    operatorIdList: '', // 运营商ID
    payTypeIdList: '', //  支付类型ID
    state: '', //          订单状态
    addCounts: '',
    endCounts: '',
    addPayTime: '', //     开始支付时间
    endPayTime: '', //     结束支付时间
    addEndTime: '', //     开始到期时间
    endEndTime: '', //     结束到期时间
    addPayAmount: '', //   开始支付金额
    endPayAmount: '', //   结束支付金额
    cards: '',
    sortName: '',
    sortType: '',
  })
  const tableLoading = ref(false)
  const tables = reactive({
    tableLoading: false,
    bordered: false,
    striped: false,
    expand: [1],
    isExpand: false,
  })
  const tableColumns: any = reactive({
    list: [
      {
        title: 'ID',
        key: 'id',
        dataIndex: 'id',
        checked: true,
        width: 100,
      },
      {
        title: '客户账号',
        key: 'userName',
        dataIndex: 'userName',
        checked: true,
        width: 130,
      },
      {
        title: '卡号',
        key: 'card',
        dataIndex: 'card',
        checked: true,
        width: 270,
      },
      // {
      //   title: '支付途径',
      //   key: 'type',
      //   dataIndex: 'type',
      //   checked: true,
      //   width: 100,
      // },
      {
        title: '会员名称',
        key: 'vipName',
        dataIndex: 'vipName',
        checked: true,
        width: 150,
      },
      {
        title: '充值金额',
        key: 'payment_amount',
        dataIndex: 'payment_amount',
        checked: true,
        width: 120,
        sortable: {
          sortDirections: ['ascend', 'descend'],
          sorter() {
            return true
          },
        },
      },
      {
        title: '会员时间',
        key: 'couponCount',
        dataIndex: 'couponCount',
        checked: true,
        width: 100,
      },
      {
        title: '订单状态',
        key: 'state',
        dataIndex: 'state',
        checked: true,
        width: 100,
      },
      {
        title: '充值时间',
        key: 'payTime',
        dataIndex: 'payTime',
        checked: true,
        width: 190,
      },
      {
        title: '开始时间',
        key: 'addTime',
        dataIndex: 'addTime',
        checked: true,
        width: 190,
      },
      {
        title: '过期时间',
        key: 'endTime',
        dataIndex: 'endTime',
        checked: true,
        width: 190,
      },
      {
        title: '退款时间',
        key: 'refundTime',
        dataIndex: 'refundTime',
        checked: true,
        width: 190,
      },
      {
        title: '退款备注',
        key: 'refundRemarks',
        dataIndex: 'refundRemarks',
        checked: true,
        width: 220,
      },
      {
        title: '操作',
        key: 'actions',
        fixed: 'right',
        dataIndex: 'actions',
        width: 70,
        align: 'center',
        checked: true,
      },
    ],
  })

  const reset = () => {
    form.value = {
      orderNumber: '', //    订单号
      card: '', //           卡号
      isZhiShu: 0, //      true直属 false所有
      userIdList: '', //     用户ID
      channelIdList: '', //  渠道ID
      seriesIdList: '', //   系列ID
      operatorIdList: '', // 运营商ID
      payTypeIdList: '', //  支付类型ID
      state: '', //          订单状态
      addCounts: '',
      endCounts: '',
      addPayTime: '', //     开始支付时间
      endPayTime: '', //     结束支付时间
      addEndTime: '', //     开始到期时间
      endEndTime: '', //     结束到期时间
      addPayAmount: '', //   开始支付金额
      endPayAmount: '', //   结束支付金额
      cards: '',
      sortName: '',
      sortType: '',
    }
    doRefresh(1)
  }
  let endTime = {}

  //跟踪API开始时间限制结束时间
  function changeTraceEnd() {
    console.log(detail.value.addTime)
    if (detail.value.addTime !== null) {
      //当前值为空 也会进行判断 所以条件最好不要非空验证
      endTime = {
        disabledDate: (time: any) => {
          return time.getTime() < new Date(detail.value.addTime).getTime() //小于开始时间的不选
        },
      }
      console.log(endTime)
    } else {
      endTime = {}
    }
  }

  const openState = (val: any) => {
    if (val.state == 1) {
      Message.error('订单已退款')
    } else {
      get({
        url: speedDetail,
        data: {
          id: val.id,
        },
      })
        .then((res) => {
          detail.value = res.data
          if (detail.value.type == 0) {
            detail.value.typeName = '余额'
          } else if (detail.value.type == 1) {
            detail.value.typeName = '支付宝'
          } else if (detail.value.type == 1) {
            detail.value.typeName = '微信'
          }
          detail.value.balance = ''
          detail.value.refundAmount = ''
          detail.value.deductionAmount = ''
          detail.value.refundRemarks = ''
          stateVisible.value = true
        })
        .catch(() => {})
    }
  }
  const closeState = () => {
    stateVisible.value = false
  }
  const refundFn = (val: any) => {
    Modal.warning({
      hideCancel: false,
      titleAlign: 'start',
      title: '确认退款',
      content: '确认执行此操作？',
      onOk: () => {
        formpost({
          url: speedTui,
          data: () => {
            return {
              id: detail.value.id,
              refundAmount: detail.value.refundAmount,
              refundRemarks: detail.value.refundRemarks,
              refundType: val,
            }
          },
        })
          .then((res) => {
            if (res.code == 0) {
              if (detail.value.type == 0 && val == 1) {
                formpost({
                  url: '/app/speed/vip/order/balance/refund',
                  data: () => {
                    return {
                      speedVipOrderId: detail.value.id,
                      refundAmount: detail.value.refundAmount,
                    }
                  },
                })
                  .then((res) => {})
                  .catch(console.log)
              }
              Message.success(res.msg)
              closeState()
              doRefresh()
            }
          })
          .catch(console.log)
      },
      onCancel: () => {},
    })
  }
  const numForm: any = ref({})
  function numFn() {
    formpost({
      url: '/app/speed/vip/order/list/statistics',
      data: {
        ...form.value,
        userIdList: form.value.userIdList.toString(),
        channelIdList: form.value.channelIdList.toString(),
        seriesIdList: form.value.seriesIdList.toString(),
        operatorIdList: form.value.operatorIdList.toString(),
        payTypeIdList: form.value.payTypeIdList.toString(),
      },
    }).then((res) => {
      numForm.value = res.data
    })
  }
  function doRefresh(value?: number) {
    // eslint-disable-next-line prettier/prettier
    tableLoading.value = true
    if (value) {
      pagination.page = value
    }

    formpost({
      url: speedOrderList,
      data: {
        page: pagination.page,
        size: pagination.pageSize,
        ...form.value,
        userIdList: form.value.userIdList.toString(),
        channelIdList: form.value.channelIdList.toString(),
        seriesIdList: form.value.seriesIdList.toString(),
        operatorIdList: form.value.operatorIdList.toString(),
        payTypeIdList: form.value.payTypeIdList.toString(),
      },
    })
      .then((res) => {
        numFn()
        tableLoading.value = false
        table.handleSuccess(res.data.list)
        pagination.setTotalSize((res.data as any).totalSize)
      })
      .catch(() => {
        tableLoading.value = false
      })
  }

  const colse = () => {
    ast.value = 0
    cardsVisible.value = false
  }
  const open = (val: any) => {
    ast.value = val
    cardsVisible.value = true
  }
  const cardBalanceExports = () => {
    loading.value = true
    useCommon
      .downLoadPosts(speedExport, form.value, '会员订单')
      .then(() => {
        loading.value = false
      })
      .catch(() => {
        loading.value = false
      })
  }

  function cardsFn() {
    const arr = card.value.split(/\n/g)
    if (ast.value == 0) {
      typeText.value = arr.toString()
    } else {
      form.value.cards = arr.toString()
    }
    cardsVisible.value = false
  }
  const detailFn = (val: any) => {
    detail.value = JSON.parse(JSON.stringify(val))
    changeTraceEnd()
    visible1.value = true
  }

  function rowClassNameFun(_record: any, index: number) {
    return index % 2 === 1 && table.striped.value ? 'table-striped' : null
  }

  const onUpdateBorder = (isBordered: boolean) => {
    tables.bordered = isBordered
  }
  function onUpdateStriped(isStriped: boolean) {
    tables.striped = isStriped
  }

  function getList() {
    useCommon.userLists().then((res: any) => {
      userList.value = res.data
      console.log(userList)
    })
  }

  function getchannel() {
    useCommon.channels1().then((res: any) => {
      channel.value = res.data
    })
  }
  function getseries() {
    useCommon.seriess().then((res: any) => {
      series.value = res.data
    })
  }
  const meal: any = ref([])
  function getMeal() {
    useCommon.mealListFn().then((res: any) => {
      meal.value = res.data
    })
  }

  const templateS: any = ref([])
  function getLists() {
    useCommon.templatesListFn(true).then((res: any) => {
      templateS.value = res.data
    })
  }

  onMounted(async () => {
    await doRefresh()
    await getList()
    await getchannel()
    await getseries()
    await getMeal()
    await getLists()
  })
</script>

<style lang="less" scoped>
  .hide {
    display: none;
  }
  .ba {
    display: flex;
    align-items: center;
    cursor: pointer;
    .aa {
      font-size: 18px;
      display: none;
    }
  }

  .ba:hover {
    display: flex;
    align-items: center;
    cursor: pointer;
    .aa {
      font-size: 18px;
      display: block;
      width: 18px;
    }
  }
  :deep(.arco-table-td-content button) {
    padding: 0px !important;
    margin-right: 8px;
    background: none !important;
  }
</style>
